package com.cloudkinto.controller.warehouse;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.warehouse.WarehouseQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.utils.dict.StaticDict;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.warehouse.WarehouseService;
import com.cloudkinto.vo.warehouse.ChannelWarehouseVo;
import com.cloudkinto.vo.warehouse.CompanyWarehouseVo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-10-29
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "仓库表模块")
@RequestMapping("/api/admin/oms/warehouse")
public class WarehouseOmsController extends BaseController {
    private final WarehouseService warehouseService;


    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "仓库表根据id查看详情", notes = "仓库表根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", warehouseService.detail(id));
    }

    @GetMapping("/pageInit")
    @ApiOperation(value = "仓库表查询初始化", notes = "仓库表查询初始化")
    public SingleResult<Map<String, Object>> pageInit() {
        return warehouseService.pageInit(getTenantId());
    }


    @UserSessionRequired
    @GetMapping("/list")
    @ApiOperation(value = "仓库表查询", notes = "仓库表查询")
    public SingleResult list() {
        WarehouseQueryBo bo = new WarehouseQueryBo();
        bo.setTenantId(getTenantId());
        bo.setUserId(getCurrentUserId());
        bo.setSource(StaticDict.System_Source.OMS.getValue());
        return SingleResult.success("查询成功", warehouseService.getList(bo));
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "仓库表查询（分页）", notes = "仓库表查询（分页）")
    public PageResult listPage(@RequestBody WarehouseQueryBo bo) {
        bo.setTenantId(getTenantId());
        bo.setUserId(getCurrentUserId());
        bo.setSource(StaticDict.System_Source.OMS.getValue());
        return warehouseService.getListPage(bo);
    }


    @UserSessionRequired
    @GetMapping("/getWarehouseListForChannel")
    @ApiOperation(value = "物流渠道设置发货地址-获取仓库列表", notes = "仓库表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channelId", value = "物流渠道id"),
    })
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ChannelWarehouseVo.class))
    public SingleResult getWarehouseListForChannel(Long channelId) {
        return SingleResult.success("查询成功", warehouseService.getWarehouseListForChannel(channelId, getTenantId()));
    }


    @UserSessionRequired
    @GetMapping("/getWarehouseListForBindAddress")
    @ApiOperation(value = "物流渠道新增-获取仓库列表", notes = "仓库表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channelId", value = "物流渠道id"),
    })
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ChannelWarehouseVo.class))
    public SingleResult getWarehouseListForBindAddress(Long channelId) {
        return SingleResult.success("查询成功", warehouseService.getWarehouseListForBindAddress(channelId, getTenantId()));
    }


    @UserSessionRequired
    @GetMapping("/getWarehouseCompany")
    @ApiOperation(value = "客户列表新增-可用仓库", notes = "客户列表编辑-可用仓库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "客户id"),
    })
    @ApiResponses(@ApiResponse(code = 200, message = "", response = CompanyWarehouseVo.class))
    public SingleResult getWarehouseCompany() {
        return SingleResult.success("查询成功", warehouseService.getWarehouseCompanyForAddInit(null, getTenantId()));
    }
}

